﻿/****************************************************************************
Copyright (c) 2014-2015 凌惊雪 微信:Lingjingxue 邮箱:lingjingxue@sina.com QQ:271487457

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/

using UtilLib;
using UtilPublic.ServerLoger;
using ServerBase.DataBaseRedis;
using ServerBase.Protocol;
using ServerBase.Other;
using System.Collections.Generic;
using static UtilPublic.Redis.ServerRedis;
using UtilPublic.Serialization;
using static ServerBase.Config.Conf;
using ServerBase.Service;
using UtilPublic.Mysql;
using static ServerBase.DataBaseRedis.RdsTxt;
using static ServerBase.Service.BaseDispatch;
using ServerBase.Config;
using ServerBase.IniFile;
using System;
using static ServerBase.IniFile.IniConf;
using ServerPublic.PubObject;
using System.Net;
using ServerPublic.Data;
using System.Linq;

namespace ServerPublic.Manager
{
    /// <summary>
    /// 
    /// </summary>
    public static class PubUserMgr
    {
        //获取用户
        public static bool GetUser(string Account, out User user)
        {
            user = new User()
            {
                Account = Account,
            };
            if (user.Load())
            {
                return true;
            }
            return false;
        }
        //获取账号通过Uuid
        public static string GetUserAccount(long Uuid)
        {
            return AHashGet(RdsUserUuidAccount, Uuid);
        }
        //判断服务器登录锁定
        public static bool CheckRestrictLogin(string ipaddress)
        {
            if (BaseServerInfo.RestrictLogin)
            {
                var ip = ipaddress.ToString();
                if (BaseServerInfo.CfgPlatform.IpUnlock.Contains(ip))
                {
                    return false;
                }
                return true;
            }
            return false;
        }

        //用户在不同服务器的Puid User:Puid:<Uuid> -- ConfigId -- Puid
        //存储 
        public static void SaveUuidPuid(long Uuid, int ConfigId, long Puid)
        {
            AHashSet($"{RdsUserPuid}:{Uuid}", ConfigId, Puid);
        }
        //读取
        public static long GetUuidPuid(long Uuid, int ConfigId)
        {
            return AHashGet($"{RdsUserPuid}:{Uuid}", ConfigId).ToLong();
        }
        

        
    }
}